const buildTool = require('./build-chip/main-chip')

Object.prototype.addTemplate = function (node) {
    return this.froStr + node.Str + this.backStr;
}
Object.prototype.joinTemplate = function (node) {
    return this.froStr + node.Str + this.backStr;
}

function buildTemplate(chipItem,packInfo) {
    return '';
    if(!chipItem) return '';

    let str = ''
    if(chipItem.items){
        for (let i = 0,len = chipItem.items; i < len; i++) {
            let froItemNode = null
            let backItemNode = null
            if(chipItem.itemType){
                froItemNode = buildTool[chipItem.type](chipItem,packInfo);
            }
            if(chipItem.type){
                backItemNode = buildTool[chipItem.itemType](chipItem,packInfo);
            }
            froItemNode.addTemplate(backItemNode.addTemplate(buildTemplate(chipItem,packInfo)))
        }

    }else {
        return froItemNode.addTemplate(backItemNode)
    }


    return packInfo;
}

function templatPack(packInfo){
    return '';
}

/**
 * @param {Object} fileItem - 生成文件的配置
 * @returns {string}
 */
function compileFile(fileItem) {
    let packInfo = {
        templateStr : '',
        data: {
            main: {}
        },
        injectData: {},
        methods:[]
    }
    buildTemplate(fileItem.configData,packInfo);
    let vueTemplate = templatPack(packInfo);
    // console.log("fileItem.configData")
    return Buffer.from(vueTemplate);


    console.log('compileFile')
    let size = 100009999;
    let type = 'vue';

    return `
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <span>fileSize:${size}</span>
    <span>fileType:${type}</span>
    <span>用为丹佛哀伤菲尼萨两地那</span>
</body>
</html>
    `
}

module.exports = {
    compileFile
}
